package com.link.base.task;

import com.link.base.base.alert.service.AlertService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.link.core.util.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author ninglanhao
 * @date 2019/5/30 16:07
 */
@JobHandler(value = "executeAlertJobHandler")
@Component
public class TaskAlertExecute extends BaseLinkJobHandler {

    @Resource
    private AlertService alertService;

    @Override
    public ReturnT<String> execute(String params) throws Exception {
        try {
            XxlJobLogger.log("预警执行开始......");
            XxlJobLogger.log("预警执行开始时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            //设置登录信息
            super.setLogin(params);
            alertService.executeAlert();
            XxlJobLogger.log("预警执行结束时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            //返回成功
            return SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return FAIL;
        }
    }
}
